package com.ruoyi.article.mapper;

import java.util.List;
import com.ruoyi.article.domain.Article;
import com.ruoyi.article.domain.vo.ArticleVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 文章管理Mapper接口
 *
 * @author ruoyi
 * @date 2025-05-22
 */
@Mapper
public interface ArticleMapper
{
    /**
     * 查询文章管理
     *
     * @param articleId 文章管理主键
     * @return 文章管理
     */
    public Article selectArticleByArticleId(Long articleId);
    @Select("SELECT \n" +
            "    article.article_id AS articleId,\n" +
            "    article.title AS title,\n" +
            "    article.content,\n" +
            "    article.click_count AS clickCount,\n" +
            "    article.create_time AS createTime,\n" +
            "    article.update_time AS updateTime,\n" +
            "    article.status,\n" +
            "    sys_user.nick_name AS userId, -- 替换用户 ID 为用户昵称\n" +
            "    article_category.category_name AS categoryId -- 替换分类 ID 为分类名称\n" +
            "FROM\n" +
            "    article\n" +
            "INNER JOIN sys_user ON article.user_id = sys_user.user_id\n" +
            "INNER JOIN article_category ON article.category_id = article_category.category_id\n" +
            "WHERE \n" +
            "    (#{title} IS NULL OR article.title LIKE CONCAT('%', #{title}, '%'))\n" +
            "    AND (#{status} IS NULL OR article.status = #{status})\n" +
            "    AND (#{categoryId} IS NULL OR article_category.category_id = #{categoryId})")
    public List<ArticleVO> selectArticeVO(Article article);
    @Select("SELECT\n" +
            "    article.article_id AS articleId,\n" +
            "    article.title AS title,\n" +
            "    article.content,\n" +
            "    article.click_count as clickCount,\n" +
            "    article.create_time as createTime,\n" +
            "    article.update_time as updateTime,\n" +
            "    article.status,\n" +
            "    sys_user.nick_name AS userId, -- 替换用户 ID 为用户昵称\n" +
            "    article_category.category_name AS categoryId -- 替换分类 ID 为分类名称\n" +
            "FROM\n" +
            "    article\n" +
            "INNER JOIN sys_user ON article.user_id = sys_user.user_id\n" +
            "INNER JOIN article_category ON article.category_id = article_category.category_id\n" +
            "where article.user_id = #{userId} \n"+
            "    AND(#{title} IS NULL OR article.title LIKE CONCAT('%', #{title}, '%'))\n" +
            "    AND (#{categoryId} IS NULL OR article_category.category_id = #{categoryId})"

    )


    public List<ArticleVO> selectByUseridArticleVO(Article article);


    @Select("SELECT\n" +
            "    article.article_id AS articleId,\n" +
            "    article.title AS title,\n" +
            "    article.content,\n" +
            "    article.click_count as clickCount,\n" +
            "    article.create_time as createTime,\n" +
            "    article.update_time as updateTime,\n" +
            "    article.status,\n" +
            "    sys_user.nick_name AS userId, -- 替换用户 ID 为用户昵称\n" +
            "    article_category.category_name AS categoryId -- 替换分类 ID 为分类名称\n" +
            "FROM\n" +
            "    article\n" +
            "INNER JOIN sys_user ON article.user_id = sys_user.user_id\n" +
            "INNER JOIN article_category ON article.category_id = article_category.category_id\n" +
            "where article.category_id = #{categoryId} ")


        public List<ArticleVO>selectArticleByCategoryId(@Param("categoryId")Long categoryId);
    /**
     * 查询文章管理列表
     *
     * @param article 文章管理
     * @return 文章管理集合
     */
    public List<Article> selectArticleList(Article article);

    @Select("SELECT\n" +
            "    article.article_id AS articleId,\n" +
            "    article.title AS title,\n" +
            "    article.content,\n" +
            "    article.click_count as clickCount,\n" +
            "    article.create_time as createTime,\n" +
            "    article.update_time as updateTime,\n" +
            "    article.status,\n" +
            "    sys_user.nick_name AS userId, -- 替换用户 ID 为用户昵称\n" +
            "    article_category.category_name AS categoryId -- 替换分类 ID 为分类名称\n" +
            "FROM\n" +
            "    article\n" +
            "INNER JOIN sys_user ON article.user_id = sys_user.user_id\n" +
            "INNER JOIN article_category ON article.category_id = article_category.category_id\n" +
            "where article.article_id = #{articleId} ")
    public  ArticleVO selectArticleVoByArticleId(@Param("articleId") Long articleId);
    /**
     * 新增文章管理
     *
     * @param article 文章管理
     * @return 结果
     */
    public int insertArticle(Article article);

    /**
     * 修改文章管理
     *
     * @param article 文章管理
     * @return 结果
     */
    public int updateArticle(Article article);

    /**
     * 删除文章管理
     *
     * @param articleId 文章管理主键
     * @return 结果
     */
    public int deleteArticleByArticleId(Long articleId);

    /**
     * 批量删除文章管理
     *
     * @param articleIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteArticleByArticleIds(Long[] articleIds);
}
